<template>
  <a-table :dataSource="dataSource" :columns="columns" />
</template>

<script setup lang="ts">
import axios from 'axios';
import { ref, onMounted } from 'vue';

// 定义响应式的dataSource
const dataSource = ref([]);

const columns = [
  {
    title: '姓名',
    dataIndex: 'name',
    key: 'name',
  },
  {
    title: '年龄',
    dataIndex: 'age',
    key: 'age',
  },
  {
    title: '住址',
    dataIndex: 'address',
    key: 'address',
  },
]

// 在组件挂载时获取数据
onMounted(() => {
  axios.get('/api/home/getTableData').then(res => {
    // 将返回的数据赋值给dataSource
    dataSource.value = res.data;
  })
})
</script>

<style scoped>

</style>